CLEAN_INDIVIDUAL = $(shell find data/meta_analyses_raw/ -type f -name 'clean.R')

.PHONY: all clean wipe renv

log/balance_table.Rout: code/balance_table.R \
	log/ak.Rout \
	code/load.R \
	data/estimates.csv
	R CMD BATCH code/balance_table.R log/balance_table.Rout 

log/ak.Rout: code/ak.R \
	log/analyze.Rout \
	code/load.R \
	data/estimates.csv
	R CMD BATCH code/ak.R log/ak.Rout 

log/analyze.Rout: code/analyze.R \
	code/load.R \
	data/estimates.csv
	R CMD BATCH code/analyze.R log/analyze.Rout 

data/estimates.csv: code/prep.R \
	data/estimates_doucouliagos_2021-12-19.csv \
	data/estimates_rb_vab_mma.csv
	R CMD BATCH code/prep.R log/prep.Rout 

data/estimates_rb_vab_mma.csv: code/extract.R \
	$(CLEAN_INDIVIDUAL)
	R CMD BATCH code/extract.R log/extract.Rout 

renv:
	Rscript -e "install.packages('renv')"
	Rscript -e "renv::restore()"

wipe:
	rm -f data/estimates.csv
	rm -f data/estimates_rb_vab_mma.csv
	rm -f data/meta_analyses_clean/*.csv
	rm -f log/*.Rout
	rm -f fig/*
	rm -rf renv/library/*
	rm -rf .RData
	rm -rf Rplots.pdf


